package recursion

import problem.Problem

class Q118PascalsTriangle extends Problem {
  def generate(numRows: Int): List[List[Int]] = {
    (1 to numRows).map { n =>
      (1 to n).map(f(n, _)).toList
    }.toList
  }

  def f(i: Int, j: Int): Int = {
    if (i == 1 || j == 1 || i == j) 1
    else f(i - 1, j - 1) + f(i - 1, j)
  }

  override def test(): Unit = {
    println(generate(1))
    println(generate(2))
    println(generate(3))
  }
}
